/*
 *  dna_otamgr.h -- provide dna-system firmware OTA (module and device) management.
 *  
 *  ORIGINAL AUTHOR: Xu Chun (chun.xu@broadlink.com.cn)
 *
 *  Copyright (c) 2016 Broadlink Corporation
 */

#ifndef __DNA_OTAMGR_H
#define __DNA_OTAMGR_H

#include "dna_ota.h"

#ifdef __cplusplus
    extern "C" {
#endif

/* dna-system firmware OTA type code */
typedef enum {
    DNA_OTA_MODULE                   = 0,
    DNA_OTA_DEVICE,
    DNA_OTA_TYPE_MAX,
} dna_ota_type_e;

/* dna-system firmware OTA operation code */
typedef enum {
    DNA_OTA_SET_URL                  = 0,          /*!<  HTTP download */
    DNA_OTA_SET_DATA,                              /*!<  APP push data blocks */
    DNA_OTA_STOP,
    DNA_OTA_GET_VERSION,
    DNA_OTA_GET_REMOTE_VERSION,                    /*!<  At the same time carry upgrade link (URL) */
    DNA_OTA_GET_PROGRESS,
    DNA_OTA_SUBOPT_MAX,
} dna_ota_opt_e;

/* dna-system remote upgrade server firmware version information */
typedef struct dna_ota_remote_info {
    unsigned int fw_version;
    char url[DNA_OTA_URL_MAX_LEN];
	unsigned int auto_update;     /* Note: 0 -- disable auto update (default), * 1 -- enable auto update. */
} dna_ota_remote_info_t;

/*
*  dna-system firmware OTA operation interface.
*
*  @input: input data (input[0] = ota type, input[1] = ota opt, ...)
*  @len: input data valid length
*  @output: output buffer
*  @maxsize: output buffer maxsize
*
*  Return output valid length, if get < 0 means occurred error.
*/
int dna_ota_operate(
        const unsigned char * input, unsigned int len,
        unsigned char * output, unsigned int maxsize);

/* 
*  dna-system firmware OTA framework initialization.
*
*  Return 0 means initialize success, if return -1 means occurred error.
*/
int dna_ota_init(void);

#ifdef __cplusplus
}
#endif

#endif

